package com.zzy.mapper;

import com.zzy.domain.Category;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface CategoryMapper {
    List<Category> all();
    
    /**
     * 新增分类
     */
    @Insert("insert into category(name, sort, parent_id) values(#{name}, #{sort}, #{parentId})")
    int add(Category category);
    
    /**
     * 根据ID查询分类
     */
    @Select("select * from category where id = #{id}")
    Category getById(Integer id);
    
    /**
     * 更新分类信息
     */
    @Update("update category set name=#{name}, sort=#{sort}, parent_id=#{parentId} where id=#{id}")
    int update(Category category);
    
    /**
     * 批量删除分类
     */
    void deleteBatch(@Param("ids") List<Integer> ids);
    
    /**
     * 根据ID删除分类
     */
    @Delete("delete from category where id = #{id}")
    int delete(Integer id);
}